//package wechat.service.application
//
//import java.util.Collection
//import java.util.Date
//import org.eclipse.xtend.lib.Property
//import org.json.JSONArray
//import org.json.JSONObject
//import wechat.base.snd.encoding.JsonPut
//import wechat.base.snd.encoding.MsgEncoding
//import wechat.base.snd.util.ExecGet
//import wechat.base.snd.util.ExecPost
//import wechat.base.snd.util.PostFile
//
//import static wechat.service.application.WCServiceApp.*
//import static wechat.service.application.WCServiceAppFactory.*
//
//
//class WCServiceAppFactory{
//	private static WCServiceApp serviceApp = new WCServiceApp('wx4bfa441f37c72005','2ac3ac52493c8ce7fbf53636a19baef9')
//	def static getServiceApp(){
//		serviceApp
//	}
//}
//
////代表微信号服务号
////@Data
//class WCServiceApp{
//	@Property String grant_type = 'client_credential'
//	@Property String APP_ID
//	@Property String SECRET
//	String TOKEN=null
//	new (String appid, String secret){
//		SECRET = secret
//		APP_ID = appid
//	}
//	static String WECHAT_PLATFORM_URL = "https://api.weixin.qq.com";
//	static Long TOKEN_EXPIRATION_TIME = 7200*1000l //7200S with a buffer
//	static Date tokenTime = new Date
//	def String getToken() { 
//		if (((new Date).getTime()-tokenTime.getTime())>TOKEN_EXPIRATION_TIME||TOKEN==null){
//			print("**********get token*****")
//			val tokenUrl = WECHAT_PLATFORM_URL + "/cgi-bin/token?grant_type=" + grant_type + "&appid=" + APP_ID +"&secret=" + SECRET;
//			val JSONObject js = new JSONObject(ExecGet::excuteGet(tokenUrl));
//			js.getString("access_token")
//			this.TOKEN=js.getString("access_token")
//		}
//		TOKEN
//	}
//	def getApplicationUrl(){
//		WECHAT_PLATFORM_URL + "/cgi-bin/message/send?access_token="+ token
//	}
//	def getApplicationMediaUrl(){
//		WECHAT_PLATFORM_URL + "/cgi-bin/media/upload?access_token="+ token
//	}
////	def WCNews createNews(){
////		new WCNews(this)
////	}
////	def WCMPNews createMPNews(){
////		new WCMPNews(this)
////	}
//	//上传文件，图片等，取得mediaID
//	def WCMediaInfo uploadTmpFile(String filePath){
//		new WCMediaInfo(PostFile::uploadFile(applicationMediaUrl, filePath, "image"))
//	}
//}
//
//abstract class WCMessage{
//	protected WCApplication application
//	protected MsgEncoding encoding
//	
//	new(WCApplication application){
//		this.application = application
//		encoding = new MsgEncoding()=>[
//			setSafe("0");
//			setToAgentid(application.AGENT_ID);			
//		]
//	}
//
//	def protected void buildContents()
//	
//	def send2Users(Iterable<String> users){
//		encoding.setToUsers(users)
//		buildContents()
//		ExecPost::excuteJsonPost(application.applicationUrl,encoding.toString)
//	}
//}
//
//class WCNews extends WCMessage{
//	new(WCApplication application) {
//		super(application)
//		encoding.setMsgType("news");
//	}
//	
//	Collection<WCNewsItem> items = newArrayList
//	
//	def WCNewsItem withItem(String title){
//		new WCNewsItem(title)=>[
//			items.add(it)
//		]
//	}
//	
//	override buildContents(){
//		val JsonPut contents = new JsonPut();
//		val JSONArray ja = new JSONArray();
//		for (WCNewsItem obj : items)
//			ja.put(obj.toJson);
//		contents=>[
//			putObj("articles", ja);
//		]
//		encoding.setNews(contents)
//	}
//}
//
//class WCNewsItem{
//	@Property String title
//	@Property String description
//	@Property String url
//	@Property String picurl
//	
//	new(String title){
//		this.title = title
//	}
//	
//	def toJson(){
//		val JsonPut article = new JsonPut()
//		article.putObj("title", title);
//		if(description!=null)article.putObj("description", description);
//		if(url!=null)article.putObj("url", url);
//		if(picurl!=null)article.putObj("picurl", picurl);
//		article
//	}
//}
//
//class WCMediaInfo{
//	@Property String type
//	@Property String media_id
//	@Property String created_at
//	
//	private JSONObject js
//	
//	new(String jsonStr){
//		js = new JSONObject(jsonStr)
//		type= js.getString("type")
//		media_id= js.getString("media_id")
//		created_at= js.getString("created_at")
//	}
//}
//
//
//class WCMPNews extends WCMessage{
//	new(WCApplication application) {
//		super(application)
//		encoding.setMsgType("mpnews");
//	}
//	
//	Collection<WCMPNewsItem> items = newArrayList
//	
//	def WCMPNewsItem withItem(String title){
//		new WCMPNewsItem(title)=>[
//			items.add(it)
//		]
//	}
//	
//	override buildContents(){
//		val JsonPut contents = new JsonPut();
//		val JSONArray ja = new JSONArray();
//		for (WCMPNewsItem obj : items)
//			ja.put(obj.toJson);
//		contents=>[putObj("articles", ja);]
//		encoding.setMpNews(contents)
//	}
//}
//class WCMPNewsItem{
//	@Property String title
//	@Property String thumb_media_id
//	@Property String author
//	@Property String content_source_url
//	@Property String content
//	@Property String digest
//	@Property String show_cover_pic
//	
//	new(String title){
//		this.title = title
//		show_cover_pic="0"
//	}
//	
//	def toJson(){
//		val JsonPut article = new JsonPut()
//		article.putObj("title", title);
//		article.putObj("thumb_media_id", thumb_media_id);
//		article.putObj("author", author);
//		article.putObj("content_source_url", content_source_url);
//		article.putObj("content", content);
//		article.putObj("digest", digest);
//		article.putObj("show_cover_pic", show_cover_pic);
//		article
//	}
//}
